//
//  BaseNavigationViewController.m
//  JiCheHuiiOS
//
//  Created by 邢广范 on 2016/12/12.
//  Copyright © 2016年 邢广范. All rights reserved.
//

#import "BaseNavigationViewController.h"
#import "UIBarButtonItem+CLBarButtonItem.h"

@interface BaseNavigationViewController ()

@end

@implementation BaseNavigationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:RGB(0xFFFFFF),NSFontAttributeName:[UIFont systemFontOfSize:18.f]}];
    [[UINavigationBar appearance] setBarTintColor:RGB(0xfc567f)];
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setTranslucent:NO];
    //去除navigaiton的线
//    [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
//    [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];

    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

// 设置导航条的样式
+(void)initialize{
    
    UIBarButtonItem *barItem = [UIBarButtonItem appearance];
    
    //    [[UINavigationBar appearance] setBackgroundImage:[UIImage ImageWithColor:[DRSColorTool blackBarColor]] forBarMetrics:UIBarMetricsDefault];
    
    // 设置普通状态
    NSDictionary *dicNormal = @{
                                NSForegroundColorAttributeName:RGB(0x4A4A4A),
                                NSFontAttributeName:[UIFont systemFontOfSize:14]
                                };
    
    [barItem setTitleTextAttributes:dicNormal  forState:UIControlStateNormal];
    
    // 设置不可用状态
    NSDictionary *dicDisabled = @{
                                  NSForegroundColorAttributeName:[UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:0.7],
                                  NSFontAttributeName:[UIFont systemFontOfSize:14]
                                  };
    [barItem setTitleTextAttributes:dicDisabled  forState:UIControlStateDisabled];
}

/**
 重写这个方法的目的是拦截所有push进来的控制器
 
 @param viewController 即将push进来的控制器
 @param animated 是否有动画效果
 */
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    
    if (self.viewControllers.count > 0) {
        // 这是push进来的控制器器不是第一个控制器
        viewController.hidesBottomBarWhenPushed = YES; // 自动隐藏tabbar
        // 设置返回状态的按钮
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(back) image:@"back" highImage:@"back"];
    }
    [super pushViewController:viewController animated:animated];
}

-(void)back{
    
    [self popViewControllerAnimated:YES];
    
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
